package com.mac.macjetpackdemo.util

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent

class CycleObserver : LifecycleObserver{
    private val TAG = "CycleObserver"
    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun create(){
        log("create")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun start(){
        log("start")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun resume(){
        log("resume")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun pause(){
        log("pause")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun stop(){
        log("stop")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun destroy(){
        log("destroy")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
    fun any(){
//        log("any")
    }

    fun log(msg:String){
        Log.w(TAG, msg)
    }
}